/**
* +----------------------------------------------------------------------
* | 友得云客  - 开启房产营销新纪元
* +----------------------------------------------------------------------
* | Copyright (c) 2019~2023 优得（西安）信息科技有限公司版权所有
* +----------------------------------------------------------------------
* | Licensed 友得云客不是自由软件 未经允许不可移除相关版权
* +----------------------------------------------------------------------
* | Author: UDEVE Team <tech@udeve.cn>
* +----------------------------------------------------------------------
*/
// components/pagemaker/videos/index.js
const app = getApp()
const videoApi = require("../../../api/video")
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    config: {
      type: Object,
      default: null
    }
  },

  ready() {
    this.loadData()
  },

  /**
   * 组件的初始数据
   */
  data: {
    items: [],
    showVideo: false,
    videoUrl: '',
  },

  /**
   * 组件的方法列表
   */
  methods: {
    loadData() {
      var ids = this.data.config.ids || []
      var f = this.data.config.dataFrom || 'ids'
      var query = {}
      if (f == 'ids') {
        query.ids = ids.join(',')
      } else {
        query.per_page = 8
      }
      videoApi.getVideoList(query).then((resp) => {
        var res = resp.data.data;
        this.setData({
          items: res
        })
      })
    },
    closeVideoPopup() {
      this.setData({
        showVideo: false,
        videoUrl: ''
      })
    },

    videoHandle(e) {
      var video = e.currentTarget.dataset.video
      console.log(e, video);
      videoApi.addVideoViews(video.id)

      if (video.is_wxvideo) {
        wx.openChannelsActivity({
          finderUserName: video.wxauthor_id,
          feedId: video.wxvideo_id,
          // success: function(res) {
          //     console.log('跳转视频', res)
          // },
          // fail: function(res) {
          //     console.log('sb跳转视频', res)
          // },
        })
      } else {
        // var videoUrl = video.url
        // this.setData({
        //   videoUrl: videoUrl,
        //   showVideo: true,
        // })
        wx.navigateTo({
          url: '/pkgVideo/pages/show/index?id=' + video.id,
        })
      }

    },

  }
})